package org.dromara.learning_xq.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.learning_xq.entity.AsClassManagement;
import org.dromara.learning_xq.mapper.AsClassManagementMapper;
import org.dromara.learning_xq.service.AsClassManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AsClassManagementServiceimpl extends ServiceImpl<AsClassManagementMapper, AsClassManagement> implements AsClassManagementService {


    @Autowired
    private AsClassManagementMapper asClassManagementMapper;

    /**
     * 批量添加班级管理数据
     *
     * @param asClassManagementList 班级管理数据列表
     * @return 添加操作成功与否的结果
     */
    public boolean increaseAsClassManagement(List<AsClassManagement> asClassManagementList) {
        // 检查列表是否为空
        if (asClassManagementList == null || asClassManagementList.isEmpty()) {
            throw new IllegalArgumentException("班级管理数据列表不能为空");
        }

        // 批量插入数据
        return this.saveBatch(asClassManagementList);
    }

    /**
     * 查询班级管理信息列表
     *
     * @param asClassManagement 包含查询条件的班级管理对象，如果为null，则查询所有数据
     * @return 返回包含班级管理信息的列表
     */
    @Override
    public List<AsClassManagement> selectAsClassManagement(AsClassManagement asClassManagement) {
        // 创建一个查询包装器，用于构建动态查询条件
        QueryWrapper<AsClassManagement> queryWrapper = new QueryWrapper<>();

        // 如果传入的班级管理对象非空，则根据其属性构建查询条件
        if (asClassManagement != null) {
            // 根据班级名称构建查询条件
            if (asClassManagement.getClassName() != null) {
                queryWrapper.eq("class_name", asClassManagement.getClassName());
            }
            // 根据所属年级构建查询条件
            if (asClassManagement.getGradeAffiliation() != null) {
                queryWrapper.eq("grade_affiliation", asClassManagement.getGradeAffiliation());
            }
            // 添加其他查询条件...
        }

        // 使用构建的查询条件查询数据库，并返回查询结果
        return asClassManagementMapper.selectList(queryWrapper);
    }


}
